package csel.controller.listeners;

import java.awt.event.ActionEvent;

import csel.controller.decoders.*;
import csel.controller.dispatchers.AbstractDispatcher;
import csel.controller.factories.*;

/**
 * Reasons for Existence: to interpret actions performed via the area 
 * viewport and create appropriate command objects</br> 
 * Team Members Responsible</br>
 * Implementation: Nik, Tait</br>
 * Testing: Nik, Tait</br>
 * 
 * @author Nikolas Wolfe
 */
public class AreaViewActionListener extends AbstractActionListener
{
	//Constructor class for AreaViewActionListener
	public AreaViewActionListener(
			AbstractDispatcher modelDispatcher,
			AbstractDispatcher viewDispatcher,
			ModelCommandFactory modelCommandFactory,
			ViewCommandFactory viewCommandFactory)
	{
		// Constructs an appropriate AreaActionEventDecoder
		this.eventDecoder = new AreaActionEventDecoder(
				this, 
				modelDispatcher,
				viewDispatcher, 
				modelCommandFactory, 
				viewCommandFactory);
	}
	
	//Overrides the actionperformed method to notify the decoder
	@Override
	public void actionPerformed(ActionEvent e)
	{
		synchronized (eventDecoder)
		{
			this.actionEvent = e;
			this.eventDecoder.notify();
		}
	}

	/*
	 * -------------
	 * TESTING ONLY
	 * -------------
	 */
	public EventDecoder getEventDecoder()
	{
		return eventDecoder;
	}
}